package com.openlab.callsystem.utils.amqp;


import com.openlab.callsystem.service.MailService;
import com.openlab.callsystem.service.VerifyService;
import com.openlab.callsystem.utils.beans.MailBean;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "mail")
public class Consumer {
    @Autowired
    MailService mailService;
    @Autowired
    VerifyService verifyService;
    @Autowired
    RedisTemplate redisTemplate;
    @RabbitHandler
    public void receive(Integer windowsId) {

        String emailAddress = (String) redisTemplate.opsForValue().get("windowsId"+windowsId);
        String code = verifyService.obtainCode(emailAddress);
        MailBean mailBean=new MailBean(emailAddress,"验证码",code);
        mailService.sendSimpleMail(mailBean);
    }


}
